package visual;

import java.awt.GridBagLayout;
import javax.swing.JPanel;
import java.awt.Dimension;
import javax.swing.JButton;
import java.awt.Rectangle;
import java.awt.FlowLayout;

public class BarraDeControle extends JPanel {

	private static final long serialVersionUID = 1L;
	private JButton apagarButton = null;
	private JButton salvarButton = null;
	private JButton fecharButton = null;
	private FormularioBase formulario;  //  @jve:decl-index=0:visual-constraint="22,70"
	private JButton cancelarButton = null;
	private JButton primeiroButton = null;
	private JButton anteriorButton = null;
	private JButton proximoButton = null;
	private JButton ultimoButton = null;
	private JButton selecionarButton = null;
	private JButton novoButton = null;
	/**
	 * This is the default constructor
	 */
	public BarraDeControle() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		FlowLayout flowLayout = new FlowLayout();
		flowLayout.setAlignment(java.awt.FlowLayout.RIGHT);
		this.setLayout(flowLayout);
		this.setSize(705, 36);
		this.add(getSelecionarButton(), null);
		this.add(getPrimeiroButton(), null);
		this.add(getAnteriorButton(), null);
		this.add(getProximoButton(), null);
		this.add(getUltimoButton(), null);
		this.add(getNovoButton(), null);
		this.add(getSalvarButton(), null);
		this.add(getCancelarButton(), null);
		this.add(getApagarButton(), null);
		this.add(getFecharButton(), null);
	}

	/**
	 * This method initializes apagarButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getApagarButton() {
		if (apagarButton == null) {
			apagarButton = new JButton();
			apagarButton.setText("Apagar");
			apagarButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					getFormulario().apagarFormulario();
				}
			});
		}
		return apagarButton;
	}

	/**
	 * This method initializes salvarButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getSalvarButton() {
		if (salvarButton == null) {
			salvarButton = new JButton();
			salvarButton.setText("Salvar");
			salvarButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					formulario.salvaFormulario();
				}
			});
		}
		return salvarButton;
	}

	/**
	 * This method initializes fecharButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getFecharButton() {
		if (fecharButton == null) {
			fecharButton = new JButton();
			fecharButton.setText("Fechar");
			fecharButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					formulario.dispose();
				}
			});
		}
		return fecharButton;
	}

	public FormularioBase getFormulario() {
		return formulario;
	}

	public void setFormulario(FormularioBase formulario) {
		this.formulario = formulario;
	}

	/**
	 * This method initializes cancelarButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getCancelarButton() {
		if (cancelarButton == null) {
			cancelarButton = new JButton();
			cancelarButton.setText("Cancelar");
			cancelarButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					formulario.carregaFormulario();
				}
			});
		}
		return cancelarButton;
	}

	/**
	 * This method initializes primeiroButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getPrimeiroButton() {
		if (primeiroButton == null) {
			primeiroButton = new JButton();
			primeiroButton.setText("|<");
		}
		return primeiroButton;
	}

	/**
	 * This method initializes anteriorButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getAnteriorButton() {
		if (anteriorButton == null) {
			anteriorButton = new JButton();
			anteriorButton.setText("<");
		}
		return anteriorButton;
	}

	/**
	 * This method initializes proximoButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getProximoButton() {
		if (proximoButton == null) {
			proximoButton = new JButton();
			proximoButton.setText(">");
		}
		return proximoButton;
	}

	/**
	 * This method initializes ultimoButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getUltimoButton() {
		if (ultimoButton == null) {
			ultimoButton = new JButton();
			ultimoButton.setText(">|");
		}
		return ultimoButton;
	}

	/**
	 * This method initializes selecionarButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getSelecionarButton() {
		if (selecionarButton == null) {
			selecionarButton = new JButton();
			selecionarButton.setText("Selecionar");
		}
		return selecionarButton;
	}
	
	public void ativaBotoes(boolean selecionar, boolean navegacao, boolean novo, boolean salvar, boolean cancelar, boolean apagar){
		
		getSelecionarButton().setEnabled(selecionar);
		
		getPrimeiroButton().setEnabled(navegacao);
		getAnteriorButton().setEnabled(navegacao);
		getProximoButton().setEnabled(navegacao);
		getUltimoButton().setEnabled(navegacao);
		
		getNovoButton().setEnabled(novo);
		getSalvarButton().setEnabled(salvar);
		getCancelarButton().setEnabled(cancelar);
		getApagarButton().setEnabled(apagar);
		
	}

	public void removerBotoes(boolean selecionar, boolean navegacao, boolean novo, boolean salvar, boolean cancelar, boolean apagar){
		if(selecionar)
			this.remove(getSelecionarButton());
			
		if(navegacao){
			this.remove(getPrimeiroButton());
			this.remove(getAnteriorButton());
			this.remove(getProximoButton());
			this.remove(getUltimoButton());
		}		
		
		if(novo)
			this.remove(getNovoButton());
		if(salvar)
			this.remove(getSalvarButton());
		if(cancelar)
			this.remove(getCancelarButton());
		if(apagar)
			this.remove(getApagarButton());
	}
	/**
	 * This method initializes novoButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getNovoButton() {
		if (novoButton == null) {
			novoButton = new JButton();
			novoButton.setText("Novo");
		}
		return novoButton;
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"
